home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8986 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: kasslar@aol.com (Kasslar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: OOD problem
  5. Date: 27 Feb 1996 14:32:50 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4gvm92$11u@newsbf02.news.aol.com>
  9. References: <4fvkmt$ems@reader2.ix.netcom.com>
  10. Reply-To: kasslar@aol.com (Kasslar)
  11. NNTP-Posting-Host: newsbf02.mail.aol.com
  12.  
  13. As a design question it seems to me that if 'A' needs to know what kind of
  14. 'B' it is pointing to upon occasion then 'B's hierarchy can't do all of
  15. the work with polymorpism. 'A' must determine the specific type of 'B' at
  16. run time. This is always unpleasant but common enough to provide several
  17. popular solutions. 
  18.  
  19. You could, of course, use C++ RTTI or some compiler specific solution here
  20. but I prefer to avoid this. It sounds to me like your scenereo suffices
  21. with polymorphic behavior most of the time but presents the occasional
  22. caveat. For this prediciment I prefer keeping several pointers in A. One
  23. B*, one C*, one D* and one E*. When the object that B* points to is
  24. construced apply a specific pointer at the same time. This allows you to
  25. once again loose your concern for the specific type pointed to by B. Where
  26. polymorphic behavior does the trick use the B*. When you must make calls
  27. to specific subclass methods use the subclass pointers. If a particular
  28. subclass has no additional behavior you will require no pointer to its
  29. specific type. If a routine attempts to manipulate the B* object with an
  30. incorrect method it should find the pointer to the specific class to be
  31. NULL.
  32.  
  33. It's not a perfect solution but it cleans up the many instances of RTTI
  34. interrogation that yould otherwise go on and runs faster too.
  35.  
  36. Just MHO,
  37. Randy Abernethy
  38. ----------------------------------------
  39. Randy Abernethy
  40. Kasslar Enterprises
  41. kasslar@aol.com
  42. randya@spectralinc.com
  43. rabernethy@spectralinc.com
  44. ----------------------------------------
  45.